package com.vitaf.cash.app.ui.adapter

import android.annotation.SuppressLint
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.vitaf.cash.app.R
import com.vitaf.cash.app.weight.font.LexendBoldTextView
import com.vitaf.cash.lib.adapter.VitafRecyclerViewAdapter
import com.vitaf.cash.lib.adapter.VitafViewHolderHelper
import com.vitaf.cash.lib.shapeview.layout.VitafLinearLayout
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2025/3/3 17:49
 * @Annotation：进件流程适配器
 */
class VitafStepsApt(recyclerView: RecyclerView?) : VitafRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.vitaf_act_process_steps_item) {
    @SuppressLint("SetTextI18n")
    override fun fillData(helper: VitafViewHolderHelper, position: Int, model: JSONObject) {

        val imgStepStart = helper.getImageView(R.id.imgStepStart)
        val stepContentLayout = helper.getView<VitafLinearLayout>(R.id.stepContentLayout)
        val textStepPosition = helper.getView<LexendBoldTextView>(R.id.textStepPosition)
        textStepPosition.text = "${position + 1}"
        val imgStepComplete = helper.getImageView(R.id.imgStepComplete)
        val textStepTitle = helper.getTextView(R.id.textStepTitle)
        textStepTitle.text = model.optString("stepTitle")
        val imgStepEnd = helper.getImageView(R.id.imgStepEnd)

        imgStepStart.visibility = View.GONE
        textStepPosition.visibility = View.GONE
        imgStepComplete.visibility = View.GONE
        imgStepEnd.visibility = View.GONE
        val selectIndex = model.optInt("selectIndex", 0)

        if (position < selectIndex){//已完成
            imgStepStart.setImageResource(R.mipmap.gombe_credit_image_step_end_complete)
            textStepPosition.visibility = View.GONE
            imgStepComplete.visibility = View.VISIBLE
            textStepTitle.setTextColor(getColor(R.color.gombe_credit_ff1d1e20))
            imgStepEnd.setImageResource(R.mipmap.gombe_credit_image_step_start_complete)

            when (position) {
                0 -> {//第一个
                    imgStepStart.visibility = View.GONE
                    imgStepEnd.visibility = View.VISIBLE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.gombe_credit_33ffdc07))
                        .setRadius(4f,0f,4f,0f)
                        .intoBackground()
                }
                itemCount - 1 -> {// 最后一个
                    imgStepStart.visibility = View.VISIBLE
                    imgStepEnd.visibility = View.GONE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.gombe_credit_33ffdc07))
                        .setRadius(0f,4f,0f,4f)
                        .intoBackground()
                }
                else -> {//中间
                    imgStepStart.visibility = View.VISIBLE
                    imgStepEnd.visibility = View.VISIBLE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.gombe_credit_33ffdc07))
                        .setRadius(0f,0f,0f,0f)
                        .intoBackground()
                }
            }
        } else if (position == selectIndex){//当前进度
            imgStepStart.setImageResource(R.mipmap.gombe_credit_image_step_end_current)
            textStepPosition.visibility = View.VISIBLE
            textStepPosition.getShapeDrawableBuilder()
                .setSolidColor(getColor(R.color.gombe_credit_ff1d1e20))
                .intoBackground()

            imgStepComplete.visibility = View.GONE
            textStepTitle.setTextColor(getColor(R.color.gombe_credit_ff1d1e20))
            imgStepEnd.setImageResource(R.mipmap.gombe_credit_image_step_start_current)

            when (position) {
                0 -> {//第一个
                    imgStepStart.visibility = View.GONE
                    imgStepEnd.visibility = View.VISIBLE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.theme))
                        .setRadius(4f,0f,4f,0f)
                        .intoBackground()
                }
                itemCount - 1 -> {// 最后一个
                    imgStepStart.visibility = View.VISIBLE
                    imgStepEnd.visibility = View.GONE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.theme))
                        .setRadius(0f,4f,0f,4f)
                        .intoBackground()
                }
                else -> {//中间
                    imgStepStart.visibility = View.VISIBLE
                    imgStepEnd.visibility = View.VISIBLE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.theme))
                        .setRadius(0f,0f,0f,0f)
                        .intoBackground()
                }
            }
        } else {//未开始
            imgStepStart.setImageResource(R.mipmap.gombe_credit_image_step_end_normal)
            textStepPosition.visibility = View.VISIBLE
            textStepPosition.getShapeDrawableBuilder()
                .setSolidColor(getColor(R.color.gombe_credit_ffa8a8a8))
                .intoBackground()

            imgStepComplete.visibility = View.GONE
            textStepTitle.setTextColor(getColor(R.color.gombe_credit_ffa8a8a8))
            imgStepEnd.setImageResource(R.mipmap.gombe_credit_image_step_start_normal)

            when (position) {
                0 -> {//第一个
                    imgStepStart.visibility = View.GONE
                    imgStepEnd.visibility = View.VISIBLE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.gombe_credit_FFF9F9F7))
                        .setRadius(4f,0f,4f,0f)
                        .intoBackground()
                }
                itemCount - 1 -> {// 最后一个
                    imgStepStart.visibility = View.VISIBLE
                    imgStepEnd.visibility = View.GONE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.gombe_credit_FFF9F9F7))
                        .setRadius(0f,4f,0f,4f)
                        .intoBackground()
                }
                else -> {//中间
                    imgStepStart.visibility = View.VISIBLE
                    imgStepEnd.visibility = View.VISIBLE

                    stepContentLayout.getShapeDrawableBuilder()
                        .setSolidColor(getColor(R.color.gombe_credit_FFF9F9F7))
                        .setRadius(0f,0f,0f,0f)
                        .intoBackground()
                }
            }
        }
    }
}